$(function(){
	$('.banner_pic li').eq(0).css({'opacity':1,'transform':'scale(1)'});
	// banner轮播
	function changeBanner(){
		$('.banner_pic li').eq(index).stop().addClass('bg').animate({'opacity':'1'},300,function(){
		   $(this).css('transform','scale(1)');
			timer=setTimeout(function(){
				$('.banner .next').click()
			},4000)
		}).siblings().stop().removeClass('bg').css({'transform':'scale(1.1)'}).animate({'opacity':0.2});
		$('.banner').css('background',$('.bg').data('color'))
	}
	var index=0;
	function changeDot(){
		$('.dot li').eq(index).addClass('Checked').siblings().removeClass('Checked')
	}
	$('.banner .next').on("click",function(){
		clearTimeout(timer);
		if(index<$('.banner_pic li').length-1){
			index++;
		}
	   else{
			index=0;
		}
		changeDot();
		changeBanner();
	});
	$('.banner .prev').on('click',function(){
		clearTimeout(timer)
		if(index>0){
			index--;
		}else{
			index=$('.banner_pic li').length-1;
		}
		changeDot();
		changeBanner();
	});
	$('.banner').css('background',$('.bg').data('color'));
	$('.banner').on({
		'mouseenter':function(){
			$('.allpic button').css('display','block').eq(0).stop().animate({left:380}).next().stop().animate({right:150})
		},
		'mouseleave':function(){
			$('.allpic button').eq(0).stop().animate({left:360},function(){
				$('.allpic button').css('display','none')
			}).next().stop().animate({right:130})
		}
	});
	//设置定时器
	var timer=setTimeout(function(){$('.banner .next').click()},4000);
	$('.banner .dot li').on('mouseover',function(){
		clearTimeout(timer);
		var i=$(this).index();
		$('.banner_pic li').eq(i).stop().addClass('bg').animate({'opacity':'1'},300,function(){
			$(this).css('transform','scale(1)');
			timer=setTimeout(function(){
				$('.banner .next').click()
			},4000)
		}).siblings().stop().removeClass('bg').css({'transform':'scale(1.1)'}).animate({'opacity':0.2});
		$('.banner').css('background',$('.bg').data('color'))
		index=i;
		changeDot();
	});
	//判断悬浮导航条的位置
	var $height=$('.serve').offset().top
	$(window).scroll(function(){
		var winTop=Number($(this).scrollTop())
		if(winTop>=$height&&Number($(this).scrollTop())<=Number($('.footer').offset().top-2*$(".nav_clum").height())){
			$('.nav_clum').stop().addClass('new_nav').animate({top:"30%"})
			if(winTop>=Number($('#title1').offset().top) && winTop<Number($('#title2').offset().top)){
				$('.nav_clum .hot_s').css({"background":"rgb(102,102,102)","color":"#fff"}).siblings().css({"background":"rgb(244,244,244)","color":"#666"})
			}else if(winTop>=Number($('#title2').offset().top) && winTop<Number($('#title3').offset().top)){
				$('.nav_clum .fast').css({"background":"rgb(102,102,102)","color":"#fff"}).siblings().css({"background":"rgb(244,244,244)","color":"#666"})
			}else if(winTop>=Number($('#title3').offset().top) && winTop<Number($('#title4').offset().top)){
				$('.nav_clum .new_p').css({"background":"rgb(102,102,102)","color":"#fff"}).siblings().css({"background":"rgb(244,244,244)","color":"#666"})
			}else if(winTop>=Number($('#title4').offset().top) && winTop<Number($('#title5').offset().top)){
				$('.nav_clum .puction').css({"background":"rgb(102,102,102)","color":"#fff"}).siblings().css({"background":"rgb(244,244,244)","color":"#666"})
			}else if(winTop>=Number($('#title5').offset().top) && winTop<Number($('#title6').offset().top)){
				$('.nav_clum .like').css({"background":"rgb(102,102,102)","color":"#fff"}).siblings().css({"background":"rgb(244,244,244)","color":"#666"})
			}else if(winTop>=Number($('#title6').offset().top) && winTop<Number($('#title7').offset().top)){
				$('.nav_clum .sun').css({"background":"rgb(102,102,102)","color":"#fff"}).siblings().css({"background":"rgb(244,244,244)","color":"#666"})
			}else if(winTop>=Number($('#title7').offset().top)){
				$('.nav_clum .last').css({"background":"rgb(102,102,102)","color":"#fff"}).siblings().css({"background":"rgb(244,244,244)","color":"#666"})
			}
		}else{
			$('.nav_clum').stop().css({top:"0%"}).removeClass('new_nav')
		}
	});
	
	function Toggle(ClassName,target){
		$(ClassName).on('click',function(){
			$('body,html').animate({
	            scrollTop: $(target).offset().top
	        })
		})
	}
	
	// console.log(winTop)
	// var tarTop=Number($('#title1').offset().top);
	
	Toggle('.nav_clum .hot_s','#title1');
	Toggle('.nav_clum .fast','#title2');
	Toggle('.nav_clum .new_p','#title3');
	Toggle('.nav_clum .puction','#title4');
	Toggle('.nav_clum .like','#title5');
	Toggle('.nav_clum .sun','#title6');
	Toggle('.nav_clum .last','#title7');
});